<template>
  <a-form
    :model="formState"
    ref="formDataRef"
    name="basic"
    :label-col="{ style: 'width:100px' }"
    :wrapper-col="{ style: 'calc(100% - 100px)' }"
    autocomplete="off"
    @finish="onFinish"
    @finishFailed="onFinishFailed"
  >
    <a-form-item label="附件类型" name="objectType" :rules="[{ required: true, message: '请选择附件类型!' }]">
      <a-select v-model:value="formState.objectType" placeholder="请选择">
        <a-select-option :value="1" label="报关">报关</a-select-option>
        <a-select-option :value="2" label="其他">其他</a-select-option>
      </a-select>
    </a-form-item>
    <a-form-item label="上传文件" name="file" :rules="[{ required: true, message: '请上传文件!' }]">
      <upload-file v-model:value="formState.file" mode="/parent/" valueType="2"></upload-file>
    </a-form-item>
    <a-form-item label="客户可见" name="customerShow" :rules="[{ required: true, message: '请选择客户可见!' }]">
      <a-radio-group v-model:value="formState.customerShow">
        <a-radio :value="1">可见</a-radio>
        <a-radio :value="0">不可见</a-radio>
      </a-radio-group>
    </a-form-item>
    <a-form-item :wrapper-col="{ offset: 8, span: 16 }" class="submit-btn-form-item">
      <a-button :loading="loading" type="primary" html-type="submit">确定</a-button>
      <a-button @click="resetHandle">取消</a-button>
    </a-form-item>
  </a-form>
</template>

<script lang="ts" setup>
import { toRefs, watch } from "vue";
import InitHook from "./composables/initHook";
import OperationHook from "./composables/operationHook";
const props = withDefaults(
  defineProps<{
    visible: boolean;
    passData: ClientWaybillManagement.ListRows;
  }>(),
  {}
);
const emit = defineEmits<{
  (e: "update:visible", blo: boolean): void;
  (e: "submit"): void;
}>();
const { visible, passData } = toRefs(props);
const { formDataRef, formState, loading } = InitHook();
const { onFinish, onFinishFailed, resetFields, resetHandle } = OperationHook({
  formDataRef,
  formState,
  passData,
  emit,
  loading
});
watch(
  () => visible.value,
  (v: boolean) => {
    if (!v) {
      resetFields();
      formDataRef.value.clearValidate();
    }
  }
);
</script>
<style lang="stylus" scoped>
:deep(.ant-picker){
    width: 100%;
}
</style>
